<?php
class ChromeController extends CController{
	public function actionChromeApi(){
		if(Yii::app()->user->isGuest){
			exit(json_encode(array('flag'=>'1','info'=>'login')));
		}else{
			exit(json_encode(array('flag'=>'2','info'=>'database')));
		}
	}

	public function actionSetLogin(){
		$post = $_POST;
		unset($_POST);
		$loginFormModel = new AccountForm('login');
		$loginFormModel->email = $post['user_name'];
		$loginFormModel->password = $post['password'];
		$loginFormModel->password = md5($loginFormModel->password);
		// validate user input and redirect to the previous page if valid
		$s = $loginFormModel->login();
		if(!$s){
			exit(json_encode(array('flag'=>'1','info'=>'登录失败')));
		}
		else{
			exit(json_encode(array('flag'=>'2','info'=>'登录成功')));
		}
	}

	public function actionSaveInfo(){
		//
		$news = new News;
		$news->link_url = NC::_p('weburl','');
		$news->site_title = NC::_p('title','');
		$news->news_desc = NC::_p('cons','');
		$news->news_tag = NC::_p('tabs','');
		$validateUrlUnique = News::validateUrlUnique($news->link_url);

		if($validateUrlUnique){
			exit(json_encode(array('flag'=>false,'info'=>'已提交，不能重复提交！')));
		}

		if($news->createNews($news)){
			$news_id = $news->primaryKey;
			CacheFile::cacheThumb($news_id,$news->link_url);
			exit(json_encode(array('flag'=>true,'info'=>'保存成功')));
		}else{
			exit(json_encode(array('flag'=>false,'info'=>'保存失败')));
		}
	}

}